<template>
	<view v-if="pageShow">
		<header-top :messageInfo="{typeFlag:true,message:'推广二维码',liner:false}"></header-top>
		<view class="mainpadding">
			<view class="flexcenter" style="margin-top: 200rpx;">
				<uqrcode ref="uqrcode" canvas-id="qrcode" v-bind:value="dataurl" :options="{ margin: 10}"></uqrcode>
			</view>
			<!-- <view class="bansebtn" @click="saveimg">保存图片</view> -->
			<view class="flexbetween margin_top">
				<view class="savebtn" @click="saveimg">保存图片</view>
				<view class="savebtn" style="background-color: #00B855;" @click="shareimg">分享好友</view>
			</view>
		</view>
	</view>
</template>

<script>
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		data() {
			return {
				// dataurl:"https://xunbo.gzxbyjs.com/share?share_id="+uni.getStorageSync("user_id")
				dataurl:"",
				pageShow:false
			}
		},
		onLoad() {
			this.init()
		},
		methods: {
			shareimg(){
				this.$refs.uqrcode.toTempFilePath({
				  success: res => {
					  this.uploadImageServicefx(res.tempFilePath)
				  }
				});
			},
			uploadImageServicefx(url) {
				let _this = this;
				httpRequest.uploadFile('/api/common/upload', url).then(res => {
					this.zfshare("",res.fullurl)
				}).catch(err => {});
			},
			init(){
				httpRequest.request('/dhtapi/user/index', 'POST', {
				}, false, false, true).then(res => {
					this.dataurl = res.data.shopinfo.goods_share_url+"?staff_id="+res.data.id
					this.pageShow = true
				}).catch(err => {
					httpRequest.toast(err.msg);
				})
			},
			saveimg(){
				this.$refs.uqrcode.save({
				  success: () => {
				    uni.showToast({
				      title: '保存成功'
				    });
				  }
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.image{
		width: 400rpx;
		height: 400rpx;
		image{
			width: 100%;
			height: 100%;
		}
	}
	.bansebtn{
		margin-top: 50rpx;
		width: 100%;
		height: 90rpx;
		background: #00B855;
		border-radius: 50rpx;
		font-size: 32rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		font-family: Microsoft YaHei;
		font-weight: bold;
		color: #FFFFFF;
	}

</style>
